<script lang="ts">
export default {
  name: `User`
}
</script>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { appRouter } from '../router/router';
import AppFooter from "../components/Footer.vue";

const username = localStorage.getItem('username') || '';
/**
 * 当前时间
 */
const currentTime = ref(new Date().toLocaleString());

const updateTime = () => {
  setInterval(() => {
    currentTime.value = new Date().toLocaleString();
  }, 1000);
}


onMounted(() => {
  updateTime();
})


function handleLogout() {
  appRouter.push({ path: '/' })
  // TODO: 清除token
  localStorage.removeItem('username')
  localStorage.removeItem('password')
}
</script>

<template>
  <div class="user">
    <h1>个人中心</h1>
    <p>欢迎，{{ username }}</p>
    <p>当前时间 {{ currentTime }}</p>
    <div class="btns">
      <el-button type="primary" @click="$router.push('/home')">返回首页</el-button>
      <el-button type="primary" @click="handleLogout">注销</el-button>
    </div>
  </div>

</template>

<style scoped></style>
